<!--
 * @Author: Dagon
 * @Date: 2021-02-24 15:05:51
 * @Description: 遍历根结点下所有子节点
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="root">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
  </div>
</body>
<script>
  const rootDom = document.getElementById('root')
  // window.alert(rootDom.children)
  console.log(111, rootDom)
  console.log(222, queryChildrenDom(rootDom))
  function queryChildrenDom(root) {
    let result = []
    let queue = [root]
    while (queue.length) {
      let cur = queue.shift()
      result.push(cur)
      for (let i = 0; i < cur.children.length; i++) {
        result.push(cur.children[i])
      }
      return result
    }
  }
</script>

</html>